package algorithm.mufeng;

public class test {
	static int a[] = {1,3,6,2,5,67,8};
	
	public static void main(String[] args){
		a = sort_bubble(a);
		for(int i = 0 ; i < a.length ; i++){
			System.out.println(a[i]);
		}
		briary_search(a,3,0,a.length);
	}
	
	public static int[] sort_bubble(int[] a){
		int length = a.length;
		for(int i = length ; i > 0 ; i-- ){
			for(int j  = 0 ; j < i-1 ; j++){
				if(a[j] > a[j+1]){
					a[j] = a[j+1] ^ a[j];
					a[j+1] = a[j+1] ^ a[j];
					a[j] = a[j+1] ^ a[j];
				}
			}
		}
		return a; 
	}
	
	public static void briary_search(int[] a,int k,int start,int end){
		if(a[(start + end)/2] == k){
			System.out.println((start + end)/2); 
		}else if(a[(start + end)/2] > k){
			briary_search(a, k, start, (start + end)/2);
		}else if(a[(start + end)/2] < k){
			briary_search(a, k, (start + end)/2, end);
		}	
	}
}
